Skip to content

improved errorlog message by adding null check#13263

Open
saurabhkushwaha438 wants to merge 2 commits into
apache:mainfrom
saurabhkushwaha438:improved-errorlog-message
Open

improved errorlog message by adding null check#13263
saurabhkushwaha438 wants to merge 2 commits into
apache:mainfrom
saurabhkushwaha438:improved-errorlog-message

Conversation

@saurabhkushwaha438
Copy link
Copy Markdown

Implemented defensive null checks to prevent secondary NullPointerExceptions from masking the original VM import failure reason during VMware-to-KVM migration. for issue #13007

Changes made:

  1. UnmanagedVMsManagerImpl.java

    • Added a null guard before invoking updateImportVMTaskErrorState(...) inside the CloudRuntimeException catch block.
  2. ImportVmTasksManagerImpl.java

    • Added an early return in updateImportVMTaskErrorState(...) when the provided task object is null.

These changes ensure that the original import/conversion failure (for example missing virt-v2v or nbdkit-vddk on the target KVM host) is preserved and propagated correctly to the UI instead of being hidden by a secondary NPE during task error handling.

@DaanHoogland DaanHoogland requested review from Copilot and nvazquez and removed request for nvazquez May 27, 2026 13:07
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 0% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.11%. Comparing base (3f6866d) to head (5f54d85).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...apache/cloudstack/vm/ImportVmTasksManagerImpl.java 0.00% 19 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #13263      +/-   ##
============================================
- Coverage     18.11%   18.11%   -0.01%     
+ Complexity    16757    16749       -8     
============================================
  Files          6037     6037              
  Lines        542783   543025     +242     
  Branches      66454    66478      +24     
============================================
+ Hits          98301    98342      +41     
- Misses       433438   433625     +187     
- Partials      11044    11058      +14     
Flag Coverage Δ
uitests 3.51% <ø> (ø)
unittests 19.27% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents secondary NullPointerExceptions from masking the original VM import/conversion failure during VMware-to-KVM migration, so the UI/API can surface the real error (e.g., missing virt-v2v / nbdkit-vddk) as described in issue #13007.

Changes:

  • Add a null guard before calling updateImportVMTaskErrorState(...) from the VM import failure handler.
  • Add an early return in updateImportVMTaskErrorState(...) when the provided task is null.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java Avoids triggering a secondary NPE while handling a CloudRuntimeException during import.
server/src/main/java/org/apache/cloudstack/vm/ImportVmTasksManagerImpl.java Makes task error-state updates resilient to null task objects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


@Override
public void updateImportVMTaskErrorState(ImportVmTask importVMTask, ImportVmTask.TaskState state, String errorMsg) {
if (importVMTask == null) {
Comment thread server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 2 changed files in this pull request and generated 3 comments.

logger.debug("Creating import VM task entry for VM: {} for account {} on zone {} " +
"from the vCenter: {} / datacenter: {} / source VM: {}",
"from the vCenter: {} / datacenter: {} / source VM: {}",
sourceVMName, owner.getAccountName(), zone.getName(), displayName, vcenter, datacenterName);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not actual change that i made , it is just a formatting to pass CI build because maven build enforces strict checkstyle rules.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sourceVMName, owner.getAccountName(), zone.getName(), displayName, vcenter, datacenterName);
sourceVMName, owner.getAccountName(), zone.getName(), vcenter, datacenterName, displayName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don’t worry about it @saurabhkushwaha438 . you can apply the suggestion (mine is better than co-pilot’s ;) ) or just resolve.

Comment on lines +155 to 156
importVMTaskVO.getDisplayName(),
importVMTaskVO.getVcenter(), importVMTaskVO.getDatacenter(), step);
Comment on lines 2046 to 2052
} catch (CloudRuntimeException e) {
logger.error(String.format("Error importing VM: %s", e.getMessage()), e);
importVmTasksManager.updateImportVMTaskErrorState(importVMTask, ImportVmTask.TaskState.Failed, e.getMessage());
ActionEventUtils.onCompletedActionEvent(userId, owner.getId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_IMPORT,
cmd.getEventDescription(), null, null, 0);
importVmTasksManager.updateImportVMTaskErrorState(importVMTask, ImportVmTask.TaskState.Failed,
e.getMessage());
ActionEventUtils.onCompletedActionEvent(userId, owner.getId(), EventVO.LEVEL_ERROR,
EventTypes.EVENT_VM_IMPORT, cmd.getEventDescription(), null, null, 0);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants